home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dbase / lib19.zip / NAVIGATE.PRG < prev    next >
Text File  |  1992-06-25  |  29KB  |  751 lines

  1. *-------------------------------------------------------------------------------
  2. *-- Program...: NAVIGATE.PRG
  3. *-- Programmer: Ken Mayer (KENMAYER)
  4. *-- Date......: 06/25/1992
  5. *-- Notes.....: These are interesting functions designed to help out in 
  6. *--             navigation ... see the file: README.TXT for details on the
  7. *--             use of this library file. 
  8. *--             NOTE -- a few functions have been added into this library
  9. *--             that are duplicated elsewhere (other library files). This is
  10. *--             due to a limitation with dBASE IV, 1.5's handling of libraries.
  11. *--             These functions are (and are from):
  12. *--             STRIP2VAL()   from STRINGS.PRG
  13. *--             STRIPVAL()
  14. *--             STRPBRK()
  15. *--             HAV()         from TRIG.PRG
  16. *--             AHAV()
  17. *--             CSCH()
  18. *--             SINH()
  19. *-------------------------------------------------------------------------------
  20.  
  21. FUNCTION Correct
  22. *-------------------------------------------------------------------------------
  23. *-- Programmer..: Jay Parsons (JPARSONS)
  24. *-- Date........: 03/01/1992
  25. *-- Notes.......: Correction of direction - adjusts direction given, in degrees,
  26. *--               by second number of degrees.  Use to convert a compass
  27. *--               direction to magnetic using deviation as the second argument,
  28. *--               or magnetic to true using variation as the second argument.
  29. *--               Returns a direction in degrees.
  30. *--
  31. *--               A westerly second argument may be given either as a negative
  32. *--               number or as a character value containing "W".  If second
  33. *--               argument is character-type but contains a negative value,
  34. *--               effect of presence or absence of "W" is reversed.  That is,
  35. *--               "-20 W" is treated like "20 E" or the number 20.
  36. *-- Written for.: dBASE IV, 1.1
  37. *-- Rev. History: None
  38. *-- Calls.......: None
  39. *-- Called by...: Any
  40. *-- Usage.......: Correct(<nDirection>,<xCorrection>)
  41. *-- Example.....: ?Correct(50,"-10 E")
  42. *-- Returns.....: Numeric (direction in degrees)
  43. *-- Parameters..: nDirection  = Heading
  44. *--               xCorrection = amount to 'correct' by, may be numeric or
  45. *--                             character, see above under 'Notes'.
  46. *-------------------------------------------------------------------------------
  47.  
  48.     parameters nDirection, xCorrection
  49.     private nCval
  50.     if type( "xCorrection" ) = "C"
  51.       nCval = val( xCorrection )
  52.       if "W" $ upper( xCorrection )
  53.         nCval = - nCval
  54.       endif
  55.     else
  56.       nCval = xCorrection
  57.     endif
  58.     
  59. RETURN mod( 360 + nDirection + nCval, 360 )
  60. *-- EoF: Correct()
  61.  
  62. FUNCTION UnCorrect
  63. *-------------------------------------------------------------------------------
  64. *-- Programmer..: Jay Parsons (JPARSONS)
  65. *-- Date........: 03/01/1992
  66. *-- Notes.......: Uncorrection of direction - adjusts direction given, in 
  67. *--               degrees, by second number of degrees.  The inverse of 
  68. *--               correct(), see above. Use to convert a true direction to 
  69. *--               magnetic using variation as the second argument, or magnetic
  70. *--               to compass using deviation as the second argument.
  71. *-- Written for.: dBASE IV, 1.1
  72. *-- Rev. History: None
  73. *-- Calls.......: None
  74. *-- Called by...: Any
  75. *-- Usage.......: UnCorrect(<nDirection>,<xUnCorr>)
  76. *-- Example.....: ?UnCorrect(50,"-10 E")
  77. *-- Returns.....: Numeric (direction in degrees)
  78. *-- Parameters..: nDirection = Heading
  79. *--               xUnCorr    = amount to 'uncorrect' by, may be numeric or
  80. *--                             character, see above under 'Notes'.
  81. *-------------------------------------------------------------------------------
  82.  
  83.     parameters nDirection, xUncorr
  84.     private nCval
  85.     if type( "xUncorr" ) = "C"
  86.       nCval = val( xUncorr )
  87.       if "W" $ upper( xUncorr )
  88.         nCval = - nCval
  89.       endif
  90.     else
  91.       nCval = xUncorr
  92.     endif
  93.     
  94. RETURN mod( 360 + nDirection - nCval, 360 )
  95. *-- EoF: UnCorrect()
  96.  
  97. FUNCTION XAngle
  98. *-------------------------------------------------------------------------------
  99. *-- Programmer..: Jay Parsons (JPARSONS)
  100. *-- Date........: 03/01/1992
  101. *-- Notes.......: Angle in degrees ( <= 90 ) at which two vectors in
  102. *--               degrees intersect.
  103. *-- Written for.: dBASE IV, 1.1
  104. *-- Rev. History: None
  105. *-- Calls.......: None
  106. *-- Called by...: Any
  107. *-- Usage.......: XAngle(<nVector1>,<nVector2>)
  108. *-- Example.....: ?UnCorrect(20,240)
  109. *-- Returns.....: Numeric (direction in degrees)
  110. *-- Parameters..: nVector1 = First angle
  111. *--               nVector2 = Second angle
  112. *-------------------------------------------------------------------------------
  113.  
  114.     parameters nVector1, nVector2
  115.     private nResult
  116.     nResult = abs( nVector1 - nVector2)
  117.     do case
  118.       case nResult > 270
  119.             nResult = 360 - Result
  120.       case nResult > 180
  121.         nResult = nResult - 180
  122.       case nResult > 90
  123.         nResult = 180 - nResult
  124.     endcase
  125.     
  126. RETURN nResult
  127. *-- EoF: XAngle()
  128.  
  129. FUNCTION LeftWind
  130. *-------------------------------------------------------------------------------
  131. *-- Programmer..: Jay Parsons (JPARSONS)
  132. *-- Date........: 03/01/1992
  133. *-- Notes.......: Whether effect of second vector on first is from the
  134. *--               left or the right.  Returns .T. if from the left, else .F.
  135. *--               Expects vectors in degrees.
  136. *--
  137. *--               For convenience in aviation calculations, the second
  138. *--               argument is expected as the direction FROM which
  139. *--               the wind or current is coming, not the direction TO
  140. *--               which it is going.  If the contrary sense
  141. *--               is more convenient, change the "=" sign in the
  142. *--               function to "#".
  143. *-- Written for.: dBASE IV, 1.1
  144. *-- Rev. History: None
  145. *-- Calls.......: None
  146. *-- Called by...: Any
  147. *-- Usage.......: LeftWind(<nCourse>,<nWindFrom>)
  148. *-- Example.....: ?LeftWind(20,240)
  149. *-- Returns.....: Numeric (direction in degrees)
  150. *-- Parameters..: nCourse   = Direction of heading ...
  151. *--               nWindFrom = Direction wind or current is coming from
  152. *-------------------------------------------------------------------------------
  153.  
  154.     parameters nCourse, nWindfrom
  155.     
  156. RETURN ( nCourse > nWindfrom ) = ( abs( nCourse - nWindfrom ) < 180 )
  157. *-- EoF: LeftWind()
  158.  
  159. FUNCTION TailWind
  160. *-------------------------------------------------------------------------------
  161. *-- Programmer..: Jay Parsons (JPARSONS)
  162. *-- Date........: 03/01/1992
  163. *-- Notes.......: Whether effect of second vector on first is additive
  164. *--               or subtractive ( from behind or from ahead ).
  165. *-- 
  166. *--               For convenience in aviation calculations, the second
  167. *--               argument is expected as the direction FROM which
  168. *--               the wind or current is coming, not the direction TO
  169. *--               which is going.  If the contrary sense
  170. *--               is more convenient, change the "<" sign in the
  171. *--               function to ">".
  172. *-- Written for.: dBASE IV, 1.1
  173. *-- Rev. History: None
  174. *-- Calls.......: None
  175. *-- Called by...: Any
  176. *-- Usage.......: TailWind(<nCourse>,<nWindFrom>)
  177. *-- Example.....: ?TailWind(20,240)
  178. *-- Returns.....: Numeric (direction in degrees)
  179. *-- Parameters..: nCourse   = Direction of heading ...
  180. *--               nWindFrom = Direction wind or current is coming from
  181. *-------------------------------------------------------------------------------
  182.  
  183.     parameters nCourse, nWindfrom
  184.     
  185. RETURN ( abs( abs( nCourse - nWindfrom ) - 180 ) < 90 )
  186. *-- EoF: TailWind()
  187.  
  188. FUNCTION Heading
  189. *-------------------------------------------------------------------------------
  190. *-- Programmer..: Jay Parsons (JPARSONS)
  191. *-- Date........: 03/01/1992
  192. *-- Notes.......: Heading required to make good a course.
  193. *--               If using this for boating and the direction of set is
  194. *--               more convenient than the direction from which
  195. *--               it is coming, apply mod( 180 + direction, 360 )
  196. *--               to the fourth argument before calling.
  197. *-- Written for.: dBASE IV, 1.1
  198. *-- Rev. History: None
  199. *-- Calls..